<template>
  <div class="proStirage">
    <div class="header">
      <div class="header-name">
        <search
          :options="selectData"
          :search-son="searchSon"
          :msg="tacitly"
          @seek="collect"
          @hand="handleQuerySonClass"
        />
        <el-button
          type="primary"
          class="btn"
          size="mini"
          @click="handleQuerySonClass"
        >
          {{ $t('btn.search') }}
        </el-button>
        <el-button
          type="primary"
          size="mini"
          @click="handleExport"
        >
          {{ $t('btn.toExcel') }}
        </el-button>
        <filtration
          :ftype="ftype"
          :msg="tacitly"
          :select-data="selectData"
          :table-header="tableHeader1"
          :detail-header="tableHeader"
          @seachData="handleQuerySonClass"
        />
      </div>
    </div>
    <div class="table-content">
      <jc-table
        :table-data="tableData"
        :table-header="tableHeader"
        :table-height="tableHeight"
        table-selection
        sortable
        get-row-keys="fentryId"
        :get-summaries="getSummaries"
        show-summary
        @clickRow="pushDetail"
      >
        <!--        单据编号-->
        <template v-slot:tagSlot="col">
          <el-link type="primary" @click="pushDetail(col.scope.row)">
            {{ col.scope.row.fbillNo }}
          </el-link>
        </template>
        <!--    物料编码    -->
        <template v-slot:orderSlot="col">
          <el-link type="primary" @click="jumpMateriel(col.scope.row)">
            {{ col.scope.row.fnumber }}
          </el-link>
        </template>
        <!--        审核状态-->
        <template v-slot:btnState="col">
          {{ col.scope.row.orderStatus }}
        </template>
      </jc-table>
      <cardTab :tab-arr="tabArr" @search="handleQueryBomList" />
    </div>
    <!--    分页器-->
    <div class="footer">
      <jc-pagination
        :total="total"
        :page.sync="currentPage"
        :limit.sync="size"
        @pagination="handleGetUntreated"
      />
    </div>
  </div>
</template>

<script>
import {
  queryPrdInStockList1
} from '@/api/production/productionList'
import search from '@/components/Search'
import searData from '@/components/Search/mixin'
import { export_json_to_excel, formatJson } from '@/utils/Export2Excel'
import { toMxBmina } from '@/components/ToMxamineState'
import filtration from '@/components/filtration'
import picker from '@/components/Search/picker'

export default {
  name: 'ProSupplement',
  components: {
    cardTab: () => import('@/components/cardTab'),
    search,
    filtration
  },
  mixins: [searData, picker],
  props: {
    list: {
      type: Array,
      default: function() {
        return []
      }
    }
  },
  data() {
    return {
      upDownVis: false,
      cha: '',
      fentryData: [],
      ftype: 25,
      total: 0, // 总条目
      currentPage: 1, // 当前页
      size: 200, // 每页显示多少条数据
      proData: [],
      tableHeight: '70vh',
      fbiVal: '',
      tabArr: [
        { label: '餐台', name: '1-1' },
        { label: '餐椅', name: '1-7' },
        { label: '软体', name: '2-3' },
        { label: '下架', name: '2-2' },
        { label: '台面', name: '2-1-11' },
        { label: '面板包', name: '2-1-01' },
        { label: '中柱包', name: '2-1-02' },
        { label: '底盘包', name: '2-1-04' },
        { label: '脚箱包', name: '2-1-03' },
        { label: '脚管/脚架包', name: '2-1-13' }
      ],
      // 表头
      tableData: [], // 生产领料数据
      tableHeader: [
        { label: this.$t('market.rkdh'), type: 'tag', prop: 'fbillNo', width: '120px' },
        { label: this.$t('market.mobillNo'), prop: 'fmobillNo', width: '120' },
        { label: this.$t('market.proOrderSeq'), prop: 'fmoentrySeq', width: '80' },
        { label: this.$t('market.orderDate'), prop: 'fdate', width: '80' },
        { label: this.$t('market.orderStatus'), type: 'state', prop: 'orderStatus', width: '100' },
        { label: this.$t('market.salKhddh'), prop: 'salKhddh', width: '110' },
        { label: this.$t('market.fmodel'), prop: 'fmodel', width: '100' },
        { label: this.$t('market.productmodel'), prop: 'fproductmodel', width: '110' },
        { label: this.$t('market.fmaterial'), type: 'order', prop: 'fnumber', width: '110px' },
        { label: this.$t('shop.fname2'), prop: 'fname' },
        { label: this.$t('market.plaint'), prop: 'fworkshop' },
        { label: this.$t('market.specificaTion'), prop: 'fspecificaTion' },
        { label: this.$t('market.fdescripTion'), prop: 'fdescripTion', minWidth: '200px' },
        { label: this.$t('market.funit'), prop: 'funitName', width: '80' },
        { label: this.$t('market.appQty'), prop: 'fmustQty', align: 'right', width: '80' },
        { label: this.$t('market.realQty'), prop: 'frealQty', align: 'right', width: '80' },
        { label: this.$t('market.orderNumber'), prop: 'fqty', align: 'right', width: '80' },
        { label: this.$t('market.purinstockqty'), prop: 'fcompleteqty', align: 'right', width: '80' },
        { label: this.$t('market.stock2'), prop: 'fstockName', width: '110' },
        { label: this.$t('market.note'), prop: 'fremark', width: '100' },
        { label: this.$t('market.creator'), prop: 'fcreator' },
        { label: this.$t('market.createDate'), prop: 'fcreatedate', width: '110' }
      ],
      tableHeader1: [
        { label: this.$t('market.caAmount'), prop: 'caAmount' },
        { label: this.$t('market.realWages1'), prop: 'realWages' },
        { label: this.$t('market.realWagesprice'), prop: 'realWagesprice' }
      ]
    }
  },
  created() {
    this.benyue() // mixins picker
    setTimeout(() => {
      this.searchSon = [
        { fid: 4, field: 'fdate', seach: this.timers[0] },
        { fid: 6, field: 'fdate', seach: this.timers[1] }
      ]
    }, 100)
    // this.handleGetUntreated()
    this.tableHeader1 = this.tableHeader.concat(this.tableHeader1)
    this.tableHeight = window.innerWidth > 1440 ? 'calc(100vh - 230px)' : '73vh'
  },
  methods: {
    // 导出表格
    handleExport() {
      require.ensure([], () => {
        const tHeader = this.tableHeader.map((res) => {
          return res.label
        })
        const filterVal = this.tableHeader.map((res) => {
          return res.prop
        })
        if (this.tableData.length <= 0) {
          this.$message.warning('没有导出数据')
        } else if (this.val && this.val.length > 0) {
          const list = this.val
          const data = formatJson(filterVal, list)
          export_json_to_excel(tHeader, data, '生产入库列表')
        } else {
          queryPrdInStockList1({
            pageSize: 100000,
            pageNum: 1,
            search: this.searCollData
          }).then(res => {
            if (res.code === 0) {
              const list = res.data.list.map(item => {
                return toMxBmina(item)
              })
              const data = formatJson(filterVal, list)
              export_json_to_excel(tHeader, data, '生产入库列表')
            } else {
              this.$confirm(res.message, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'error'
              })
            }
          })
        }
      })
    },
    // 获取生产入库列表数据
    async handleGetUntreated(ev) {
      this.details = []
      if (ev && !ev.page) {
        this.details = ev
      }
      const DATA = {
        list: this.list,
        pageNum: this.currentPage,
        pageSize: this.size,
        search: this.searCollData.concat(this.details)
      }
      await queryPrdInStockList1(DATA).then(res => {
        if (res.code === 0) {
          this.tableData = res.data.list
          this.tableData.map(item => {
            return toMxBmina(item)
          })
          this.total = res.data.total
        } else {
          this.$message.error(res.message)
        }
      })
    },
    // 搜索
    handleQuerySonClass(ev) {
      this.currentPage = 1
      if (ev && ev.fname) {
        this.searchSon = ev.detail
        this.customHandle(ev)
        this.handleGetUntreated(ev.detail)
      } else {
        this.handleGetUntreated()
      }
    },
    // 成品 原材料
    handleQueryBomList(ev) {
      this.searCollData = []
      this.currentPage = 1
      this.searCollData = ev
      this.searchSon = ev
      this.handleGetUntreated()
    },
    // 详情
    pushDetail(ev) {
      const id = ev.fid
      this.$router.push({
        path: `/proStirageOrder/${id}`
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.proStirage {
  @include listBom;
  padding: 0;
  .header {
    position: relative;
    .header-name {
      width: 100%;
      .input-width {
        width: 100px;
      }
    }
    .btn {
      transform: translateY(18%);
      margin-left: 450px !important;
    }
  }
}
</style>
